//
//  registerViewController.swift
//  万才信息App
//
//  Created by 陌上互联  on 16/7/14.
//  Copyright © 2016年 万才信息. All rights reserved.
//

import UIKit

//注册界面
class registerViewController:UIViewController{
    
    @IBOutlet weak var tvUsernmae: UITextField!
    @IBOutlet weak var tvPwd1: UITextField!
    @IBOutlet weak var tvPwd2: UITextField!
    @IBOutlet weak var tvEmail: UITextField!
    
    @IBAction func pressRegister(sender: AnyObject) {
        let username=tvUsernmae.text!
        let pwd1=tvPwd1.text!
        let pwd2=tvPwd2.text!
        let email=tvEmail.text!
        
//        判断密码是否相同
        if(pwd1==pwd2){
//            检测邮箱是否填写正确
            if(checkUtil.checkEmailCorrect(email)){
//                开启等待提示
                let waiting=waitingAlertUtil(msg: "注册中")
                loginAndRegister.userRegister(username, pwd: pwd1, email: email, successCallback: { (userId) in
//                    成功了
                    waiting.stop()
//                    跳转到主页面
                    self.performSegueWithIdentifier("registerSuccess", sender: self)
                    }, failCallback: { (error) in
//                        失败了
                        waiting.stop()
                        warningAlertUtil(title: "注册失败", msg: error).show(self)
                })
                
            }else{
                 warningAlertUtil(title: "注册失败", msg: "邮箱格式错误！").show(self)
            }
        }else{
            warningAlertUtil(title: "注册失败", msg: "密码不一致！").show(self)
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    
}